package hr.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import hr.entity.MovementLog;
import hr.service.MovementLogService;
import hr.utils.Result.Result;
import hr.utils.Result.ResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 岗位调动日志 前端控制器
 * </p>
 *
 * @author zzh
 * @since 2023-12-16
 */
@Tag(name = "岗位调动日志")
@RestController
@RequestMapping("/movementLog")
public class MovementLogController {
    @Autowired
    private MovementLogService movementLogService;

    @Operation(summary = "获取岗位调动日志列表")
    @PostMapping("/getMovementLog/{page}/{limit}")
    public Result<Object> getMovementLog(@PathVariable long page,
                                         @PathVariable long limit,
                                         MovementLog movementLog) {
        Page<MovementLog> pageParam = new Page<>(page, limit);
        IPage<MovementLog> pageModel = movementLogService.selectPage(pageParam, movementLog);
        return ResultUtil.success(pageModel);
    }

    @Operation(summary = "模糊查询（姓名）")
    @PostMapping("/getMovementLogByName/{name}")
    public Result<Object> getMovementLogByName(@PathVariable String name) {
        HashMap<String, Object> map = new HashMap<>();
        List<MovementLog> movementLogList = movementLogService.findByName(name);
        map.put("movementLogList", movementLogList);
        return ResultUtil.success(map);
    }


}
